package cn.edu.nuc.crm.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.edu.nuc.crm.dao.ApplicationMapper;
import cn.edu.nuc.crm.dao.RepaymentMapper;
import cn.edu.nuc.crm.dto.PageInfo;
import cn.edu.nuc.crm.entity.Application;
import cn.edu.nuc.crm.entity.Repayment;
import cn.edu.nuc.crm.service.interfaces.RepaymentService;
@Service
public class RepaymentServiceImpl implements RepaymentService {
	@Autowired
	private RepaymentMapper repaymentMapper;
	@Autowired
	private ApplicationMapper applicationMapper;
	
	@Override
	public PageInfo pi(int current) {
		PageInfo pi = new PageInfo(current);
		int count = repaymentMapper.count();
		pi.setCount(count);
		List<Repayment> findByid=repaymentMapper.findByid(pi.getStart(), pi.getOffset());
		System.out.println("总的记录数:"+count+"--"+pi);
		pi.setList(findByid);
		return pi;
	}
	@Override
	public List<Repayment> selectByName(String accountTruename) {
		// TODO Auto-generated method stub
		List<Repayment> result=repaymentMapper.selectByName(accountTruename);
		return result;
	}
	@Override
	public Repayment selectByPrimaryKey(Integer repaymentId) {
		// TODO Auto-generated method stub
		Repayment result=repaymentMapper.selectByPrimaryKey(repaymentId);
		return result;
	}
	@Override
	public int deleteByPrimaryKey(Integer repaymentId) {
		// TODO Auto-generated method stub
		int result=repaymentMapper.deleteByPrimaryKey(repaymentId);
		return result;
	}
	@Override
	public int insert(Repayment repayment) {
		// TODO Auto-generated method stub
		int result=repaymentMapper.insert(repayment);
		return result;
	}
	@Override
	public PageInfo accountRepayment(Integer accountid, int current) {
		PageInfo pi = new PageInfo(current);
		//查询 account 的count
		int count = repaymentMapper.accountRepaymentCount(accountid);
		pi.setCount(count);
		List<Repayment> findByid=repaymentMapper.findByid2(accountid,pi.getStart(), pi.getOffset());
		System.out.println("总的记录数:"+count+"--"+pi);
		pi.setList(findByid);
		return pi;
	}
	@Override
	public PageInfo repaymentManage(int current) {
		// TODO Auto-generated method stub
		PageInfo pi = new PageInfo(current);
		//获取开始还款的条数  审核都为 1
		int count = applicationMapper.getRepaymentcount();
		pi.setCount(count);
		//获取  还款的列表数目
		List<Repayment> findByid=repaymentMapper.findByid(pi.getStart(), pi.getOffset());
		System.out.println("总的记录数:"+count+"--"+pi);
		pi.setList(findByid);
		return pi;
	}

}
